<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <canvas id="myCanvas" width="400" height="300">
        您的浏览器不支持 Canvas
    </canvas>
    <script>
        var canvas = document.getElementById('myCanvas');
        var ctx = canvas.getContext('2d');

        var posX = 20;
        var posY = 100;


        setInterval(function () {
            ctx.fillStyle = 'black';
            ctx.fillRect(0, 0, canvas.width, canvas.height); // 将画布背景设置为黑色

            posX += 1;
            posY += 0.25;

            ctx.beginPath(); // 开始绘制
            ctx.fillStyle = 'white';

            ctx.arc(posX, posY, 10, 0, Math.PI * 2, true);
            ctx.closePath(); // 结束绘制
            ctx.fill();
        }, 30);
    </script>
</body>

</html>